package com.dongdong.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdong.data.Page;
import com.dongdong.mapper.TbBrandMapper;
import com.dongdong.pojo.TbBrand;
import com.dongdong.pojo.TbBrandExample;
import com.dongdong.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private TbBrandMapper tbBrandMapper;

    @Override
    public TbBrand selectById(Long id) {
        return tbBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TbBrand> selectAll() {
        return tbBrandMapper.selectByExample(null);
    }

    @Override
    public int insert(TbBrand tbBrand) {
        return tbBrandMapper.insert(tbBrand);
    }


    @Override
    public Page<TbBrand> brandList(Integer pageNum, Integer pageSize) {
         PageHelper.startPage(pageNum,pageSize);
         List<TbBrand> brandList = tbBrandMapper.selectByExample(null);
         PageInfo<TbBrand> info = new PageInfo<>(brandList);
        return new Page<>(info.getPageNum(),info.getPageSize(),info.getTotal(),info.getPages(),info.getList());

    }

    @Override
    public int updateInfo(TbBrand tbBrand) {
        return tbBrandMapper.updateByPrimaryKey(tbBrand);
    }

    @Override
    public int deleteAll(Long[] ids) {
        TbBrandExample te = new TbBrandExample();
        TbBrandExample.Criteria criteria = te.createCriteria();
        criteria.andIdIn(Arrays.asList(ids));
        return tbBrandMapper.deleteByExample(te);
    }


}
